// Copyright (C) Kumo inc. and its affiliates.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//
#pragma once

#include <string>
#include <unordered_map>
#include <vector>

#include <pollux/dwio/common/options.h>

namespace kumo::pollux::connector::hive::iceberg {

enum class FileContent {
  kData,
  kPositionalDeletes,
  kEqualityDeletes,
};

struct IcebergDeleteFile {
  FileContent content;
  const std::string filePath;
  dwio::common::FileFormat fileFormat;
  uint64_t recordCount;
  uint64_t fileSizeInBytes;
  // The field ids for the delete columns for equality delete files
  std::vector<int32_t> equalityFieldIds;
  // The lower bounds of the in-file positions for the deleted rows, identified
  // by each column's field id. E.g. The deleted rows for a column with field id
  // 1 is in range [10, 50], where 10 and 50 are the deleted row positions in
  // the data file, then lowerBounds would contain entry <1, "10">
  std::unordered_map<int32_t, std::string> lowerBounds;
  // The upper bounds of the in-file positions for the deleted rows, identified
  // by each column's field id. E.g. The deleted rows for a column with field id
  // 1 is in range [10, 50], then upperBounds will contain entry <1, "50">
  std::unordered_map<int32_t, std::string> upperBounds;

  IcebergDeleteFile(
      FileContent _content,
      const std::string& _filePath,
      dwio::common::FileFormat _fileFormat,
      uint64_t _recordCount,
      uint64_t _fileSizeInBytes,
      std::vector<int32_t> _equalityFieldIds = {},
      std::unordered_map<int32_t, std::string> _lowerBounds = {},
      std::unordered_map<int32_t, std::string> _upperBounds = {})
      : content(_content),
        filePath(_filePath),
        fileFormat(_fileFormat),
        recordCount(_recordCount),
        fileSizeInBytes(_fileSizeInBytes),
        equalityFieldIds(_equalityFieldIds),
        lowerBounds(_lowerBounds),
        upperBounds(_upperBounds) {}
};

} // namespace kumo::pollux::connector::hive::iceberg
